//
//  MainViewController.swift
//  DataStructuresAlgorithms
//
//  Created by xiangzuhua on 2021/3/15.
//

import UIKit

class MainViewController: UIViewController,UITableViewDelegate,UITableViewDataSource {
    var tableView: UITableView?
    var data: Array<String>?
    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = UIColor.white
        self.title = "数据结构与算法"
        self.navigationItem.backButtonTitle = "返回"
        
        data = [
            ArrayModule,
            LinkListModule,
            StackModule,
            QueueModule,
            RecursionModule,
            SortModule,
            GraphModule
        ]
        tableView = UITableView(frame: self.view.bounds, style: .plain)
        tableView?.delegate = self;
        tableView?.dataSource = self;
        self.view.addSubview(tableView!)
        tableView?.tableFooterView = UIView(frame: CGRect.zero)
        
        
        let string1 = "abcdefg"
        for dostring in string1.indices {
            print(dostring)
        }
        UIApplication.shared.windows.first{$0.isKeyWindow}?.safeAreaInsets.bottom ?? 0.0 > 0.0
        for dostring in string1.unicodeScalars {
            print("\(type(of: dostring))" + "\(dostring)")
        }
        
        
        // Do any additional setup after loading the view.
    }
    
    // MARK:-tableView
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return data?.count ?? 0
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        var cell = tableView.dequeueReusableCell(withIdentifier: "tableViewCell")
        if cell == nil {
            cell = UITableViewCell(style: .default, reuseIdentifier: "tableViewCell")
        }
        let name = data?[indexPath.row]
        cell?.textLabel?.text = name
        cell!.accessoryType = .disclosureIndicator
        return cell!
    }
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        50
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        tableView.deselectRow(at: indexPath, animated: true)
        let vc = CommonSubViewController()
        vc.titleName = data?[indexPath.row]
        self.navigationController?.pushViewController(vc, animated: true)
        
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
    }
    */

}
